--- 战策二·偃甲息兵
local policy2 = fk.CreateSkill {
    name = "backarm_stop",
    tags = { Skill.Compulsory },
    dynamic_name = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
    dynamic_desc = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
}

local HG = require "packages.new_heg_diy_my.util"

Fk:loadTranslationTable{
    ["@[backarm_stop_mark]"] = "偃甲息兵",
    ["@@backarm_stop-turn"] = "偃甲息兵",
    ["backarm_stop_ask"] = "战策-偃甲息兵：你可以令你与此牌使用者依次收回装备区内所有牌且本回合不能使用装备牌",
}

policy2:addEffect(fk.TargetConfirmed, {
    anim_type = "defensive",
    can_trigger = function(self, event, target, player, data)
        local mark_name = "@[private]" .. policy2.name .. "_mark"
        local from = data.from
        return player:getMark(mark_name) ~= 0 and target == player and from ~= player and
            (#from:getCardIds("e") > 0 or #player:getCardIds("e") > 0)
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, { skill_name = "unknownpolicy", prompt = "backarm_stop_ask" })
    end,
    on_use = function(self, event, target, player, data)
        local mark_name = "@[private]" .. policy2.name .. "_mark"
        local room = player.room
        local from = data.from
        room:moveCardTo(player:getCardIds("e"), Card.PlayerHand, player, fk.ReasonJustMove, policy2.name, nil, false,
            player)
        local mark_player = player:getTableMark("@steam__mianzhou-turn")
        table.insertIfNeed(mark_player, "equip_char")
        room:setPlayerMark(player, "@@backarm_stop-turn", mark_player)

        room:moveCardTo(from:getCardIds("e"), Card.PlayerHand, from, fk.ReasonJustMove, policy2.name, nil, false, player)
        local mark_from = from:getTableMark("@steam__mianzhou-turn")
        table.insertIfNeed(mark_from, "equip_char")
        room:setPlayerMark(from, "@@backarm_stop-turn", mark_from)

        room:setPlayerMark(player, mark_name, 0)
        room:handleAddLoseSkills(player, "-backarm_stop", nil, false)
        room.logic:trigger(HG.HegLosePolicy, player, { player, policy2.name })
        local card = Fk:cloneCard("heg_backarm_stop")
        room:getVirtCardId(card)
        room:showVirtualCard(card, player, nil, room.logic:getCurrentEvent().id + 1)
    end,
})

policy2:addEffect("prohibit", {
    prohibit_use = function(self, player, card)
        return card and card.type == Card.TypeEquip and table.contains(player:getTableMark("@@backarm_stop-turn"), "equip_char")
    end,
})

return policy2
